package app.common.utils.cjt.ao;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author feizns
 * @since 2023/4/3
 */
@Data
public class CommonAo {

    /**
     * uri
     */
    @NotBlank(message = "函数uri不能为空.")
    private String method;

    /**
     * dto
     */
    private Map<String, Object> dto = new LinkedHashMap<>();

    /**
     * 映射
     * @return {@link Map}<{@link String}, {@link Object}>
     */
    public Map<String, Object> toMap() {
        return dto;
    }

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        String tmp = "{\"dto\":\"{\\\"Code\\\":\\\"99\\\",\\\"Name\\\":\\\"测试\\\"}\",\"method\":\"/tplus/api/v2/inventoryClass/Create\"}";
        CommonAo ao = objectMapper.readValue(tmp, CommonAo.class);
        System.out.println(ao);
        System.out.println(objectMapper.writeValueAsString(ao));
    }

}
